Repository navigation
Conversation
Refs #3417. Raise the native Vulkan SDPA limit from 7168 to 8192 visible keys. Shared score storage keeps the 7168-key cap. Above it, a GLOBAL_SCORES specialization of the existing decode shader stores F32 scores in a per-row, per-head region of an engine-owned score view. A request above 7168 without that view fails before dispatch. 8193 is refused, never clamped. The arena is 16 MiB for capacity 1..7168 and 32 MiB for 7169..8192. Score arithmetic, barriers and rounding are unchanged; only the score storage location differs. Host tests cover attendPlan at 7169/8192/8193, the score workspace size and overflow refusals, arena selection and budget, and request/CLI bounds. The attention contract adds BF16 and FP32 cases at 7169 and 8192 and a chunk that crosses 7168. Thanks @joshuaswarren for the capacity design and contract cases. Co-authored-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
Refs #3431. BF16 query chunks of 2..64 rows use a new three-stage prefill tile: scores, softmax and PV. Four rows and four GQA query heads share each K and V tile load. All FP32 queries, one-row decode and larger chunks keep the existing fused route. The tile keeps main's arithmetic: scale times Q before an ascending dot, the 256-lane max and sum trees, 16-key PV partials and one divide before RNE BF16. Each row's products are guarded by its own causal bound, so a future NaN or Inf value never enters an earlier row. Tile workspace is sized from the admitted capacity: 16 MiB plus 4 KiB at 8192. The attention contract adds 16 served-shape checks (rows 64/64/64/62 at prefixes 0/64/128/192, BF16 and native FP32, finite and future NaN/Inf) and three planted controls that must fail. Thanks @joshuaswarren for the tiling design and the served-shape regression. Co-authored-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com>
This was referenced Dec 5, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Vulkan SDPA: 8192 keys and tiled BF16 prefill
This carries the work from #3417 and #3431 by @joshuaswarren onto main's own Vulkan attention shader. Thank you,
@joshuaswarren, for the capacity design, the prefill tiling, the causal guard and the served-shape regression. Both
commits credit you as co-author.
What it does
Commit 1, from #3417: 8192 visible keys.
GLOBAL_SCORESspecialization ofsdpa_decode_native.compstores F32 scores in global memory.Each row and head gets its own region. A request above 7168 without that score buffer fails before dispatch.
Commit 2, from #3431: tiled BF16 prefill.
sdpa_prefill_tile.comp): scores, softmax, PV.Four rows and four GQA query heads share each K and V tile load.
scale * Qbefore an ascending dot, the 256-lane max and sum trees, 16-key PVpartials, one divide, then RNE to BF16.
native FP32 queries, finite values and future NaN/Inf. Three planted shaders must fail the byte check.
No tolerance, no rounding change, no precision option. No other backend is touched.
Checks run
Host only. We have no shader compiler and no Vulkan headers on the build host for this change.
zig fmt --check --ast-checkon all 16 changed Zig files: pass.stage3-host-testwith-Dvulkan=true: the served-shape tests run and pass (28 tests on main, 31 here). A plantederror in the served table makes them fail. The parts that need
vulkan/vulkan_core.hdid not build.tools/pr_check.py --base main: 0 errors. Lean 88 vs 88, no new import-cycle or cross-family edges.Not run: the shader builds, every GPU step, the host tests that need the Vulkan headers (attention plans at
7169/8192/8193, score workspace, prefill routing, arena sizing, request and CLI bounds), and any token, logit or
speed comparison.
Device check we ask for
@joshuaswarren, could you run this on your Vulkan GPU? We have no non-Apple Vulkan GPU to run it ourselves.
Build main and this branch with the same toolchain:
zig-out/bin/tf-attention-contract --vendor VENDOR_ID --timeout-ms 600000.Every case must pass, including the 7169/8192 cases, the 16
sdpa-servedlines and all 3 controlsCAUGHT.zig-out/bin/tf-qwen35-model --vendor VENDOR_ID --context N MODEL INPUT_IDS.npy ORACLE OUTlogits_bf16.binmust be byte-equal (cmp) between main andthis branch.
(global scores, no tile). IDs and
logits_bf16.binmust be byte-equal. Please also confirm main refuses 8192.chunk of L - 64 rows for L in 66..128. Run every prompt length 66..128 (final chunks of 2..64 rows) on main and
this branch. IDs and
logits_bf16.binmust be byte-equal for each length.alternating runs with the same settings. Please also note the peak memory at
--context 8192.Please post the GPU model, driver, commands and outputs, including any failure or timeout.